package com.p24.XMLParser;

import java.util.LinkedList;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.p24.XMLParser.entity.XMLMfoEntity;

public class XMLMfoParser extends CommonXMLParser {

	public XMLMfoParser(String XMLString) throws Exception {
		super(XMLString);
	}
	
	public LinkedList<XMLMfoEntity> getMfoInfo() throws Exception {
		LinkedList<XMLMfoEntity> xmlMfoInfo = new LinkedList<XMLMfoEntity>();
		//
		if(super.getDoc() == null)
			throw new Exception("DOC is Empty");
		NodeList banksList = super.getDoc().getElementsByTagName("BANK");
		for(int i=0; i<banksList.getLength(); i++) {
			Node bank = banksList.item(i);
			NamedNodeMap attributes = bank.getAttributes();
			
			XMLMfoEntity xmlMfoEntity = new XMLMfoEntity();
			xmlMfoEntity.setCountry(attributes.getNamedItem("COUNTRY").getNodeValue());
			xmlMfoEntity.setName(attributes.getNamedItem("NAME").getNodeValue());
			xmlMfoEntity.setCity(attributes.getNamedItem("CITY").getNodeValue());
			xmlMfoEntity.setMfo(attributes.getNamedItem("MFO").getNodeValue());
			
			xmlMfoInfo.add(xmlMfoEntity);
		}
		//
		return xmlMfoInfo;
	}

}
